<template>
	<view class="count">
		<view class="body b-f p-30">
			<view class="item f f-a-c f-j-b">
				<view class="person">
					收货人
				</view>
				<view class="right">
					<input type="text" v-model="obj.name" class="inp" placeholder="请填写收货人姓名" name="" id="">
				</view>
			</view>
			<view class="item f f-a-c f-j-b">
				<view class="person">
					联系方式
				</view>
				<view class="right">
					<input type="text" v-model="obj.phone" class="inp" placeholder="请填写收货人手机号" name="" id="">
				</view>
			</view>
			<view class="item f f-a-c f-j-b">
				<view class="person">
					所在地区
				</view>
				<view @click="show=true" class="right f f-a-c ">
					<input type="text" v-model="obj.address" disabled class="inp" placeholder="请选择省市区" name="" id="">
				</view>
				<image src="/static/youjian.png" class="youTou m-l-10" mode=""></image>
			</view>
			<view class="item  f f-a-c f-j-b">
				<view class="person">
					详细地址
				</view>
				<view class="right">
					<input type="text" v-model="obj.detilAddrees" class="inp" placeholder="请填写详细地址，具体到门牌号" name=""
						id="">
				</view>
			</view>
			<view class="item items f f-a-c f-j-b">
				<view class="person">
					设为默认地址
				</view>
				<view class="right f f-a-c f-j-f-e">
					<u-switch v-model="checked" active-color="#977961" inactive-color="#ebe2da"></u-switch>
				</view>
			</view>
		</view>
		<view class=""><u-select mode="mutil-column-auto" v-model="show" label-name="text" :list="list"
				@confirm="regionConfirm"></u-select></view>
		<!-- 下面的按钮 -->
		<view class="botBtn f f-a-c">
			<view @click="comig" class="btnDet f f-a-c f-j-c">
				删除
			</view>
			<view @click="baoCun" class="comfig f f-a-c f-j-c">
				保存
			</view>
		</view>
	</view>
</template>

<script>
	import cityJson from '@/utils/china.json';
	export default {
		data() {
			return {
				checked: false,
				show: false,
				list: cityJson,
				num: 0,
				sheng: '',
				shi: '',
				qu: '',
				item: {},
				obj: {
					detilAddrees: '',
					address: '',
					phone: '',
					name: '',
					province: '',
					city: '',
					district: ''
				}
			}
		},
		onLoad(options) {
			let n = JSON.parse(options.item)
			this.item = n
			this.obj.name = n.name
			this.obj.phone = n.mobile
			this.obj.address = n.province + '-' + n.city + '-' + n.district
			this.sheng = n.province
			this.shi = n.city
			this.qu = n.district
			this.obj.detilAddrees = n.detail
			this.checked = n.defaulted
		},
		methods: {
			// 点击删除 
			async comig() {
				let n = await this.$api.detEditList({
					id: this.item.id
				})
				this.$msg(n.msg)
				if (n.code == 200) {
					setTimeout(() => {
						uni.navigateBack()
					}, 800)
				}
			},
			regionConfirm(e) {
				console.log(e, '5555555555');
				this.obj.address = e[0].label + '-' + e[1].label + '-' + e[2].label
				this.sheng = e[0].label
				this.shi = e[1].label
				this.qu = e[2].label
			},
			// 点击保存
			async baoCun() {
				let n = await this.$api.editList({
					name: this.obj.name,
					mobile: this.obj.phone,
					province: this.sheng,
					city: this.shi,
					district: this.qu,
					detail: this.obj.detilAddrees,
					defaulted: this.checked
				}, this.item.id)
				this.$msg(n.msg)
				if (n.code == 200) {
					setTimeout(() => {
						uni.navigateBack()
					}, 800)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.botBtn {
		height: 88rpx;
		width: 90%;
		margin: 0 auto;
		margin-top: 50rpx;

		.comfig {
			flex: 1;
			height: 100%;
			background: #977961;
			border-radius: 44rpx;
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-500;
			font-weight: 500;
			text-align: center;
			color: #ffffff;
		}

		.btnDet {
			flex: 1;
			height: 100%;
			border: 1rpx solid #ebe2da;
			border-radius: 45rpx;
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-500;
			font-weight: 500;
			text-align: center;
			color: #2f2319;
			margin-right: 25rpx;
		}
	}

	.body {
		padding: 0 50rpx;
	}

	.btn {
		// position: fixed;
		// bottom: 100rpx;
		// left: 50%;
		// transform: translateX(-50%);
		width: 90%;
		margin: 0 auto;
		margin-top: 50rpx;
		height: 88rpx;
		border-radius: 44rpx;
		line-height: 85rpx;
		background: #977961;
		font-size: 30rpx;
		font-family: PingFang SC, PingFang SC-Regular;
		font-weight: 400;
		text-align: center;
		color: #ffffff;
	}

	.item {
		padding: 40rpx 0;
		border-bottom: 2rpx solid #f5f5f5;

		.person {
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-Regular;
			font-weight: 400;
			text-align: left;
			color: #000;
			flex: 1.5;
		}

		.right {
			flex: 3;

		}

		.youTou {
			width: 16rpx;
			height: 24rpx;
		}

		.inp {
			text-align: left;
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-Regular;
			font-weight: 400;
			color: #2F2319;
		}
	}

	.items {
		border: none;
		padding-bottom: 0;
	}

	.count {
		height: 100vh;
		width: 100%;
		overflow-y: auto;
		background-color: #fffefc;
	}
</style>